# coding=utf-8
__author__ = 'liubin'

from flask import render_template
from flask.views import View
from flask.ext.login import login_required
from project import app


class IndexView(View):
    """
    index 的视图
    使用可插拔视图
    """
    # 规定可访问的方法
    methods = ['GET']
    # 装饰器放的位置
    decorators = [login_required]

    def dispatch_request(self, **kwargs):
        """
        请求的处理
        :return:
        """
        # 返回到指定模板
        return render_template('index.html')


# url映射
app.add_url_rule('/', view_func=IndexView.as_view('index'))
app.add_url_rule('/user', view_func=IndexView.as_view('userlist'))
app.add_url_rule('/user/add', view_func=IndexView.as_view('useradd'))
app.add_url_rule('/user/<int:id>/edit', view_func=IndexView.as_view('useredit'))
app.add_url_rule('/role', view_func=IndexView.as_view('rolelist'))



class ConfirmView(View):
    methods = ['GET']
    def dispatch_request(self, **kwargs):
        return render_template('confirm.html')
app.add_url_rule('/confirm', view_func=ConfirmView.as_view('confirm'))